package com.jy.api.service.impl;

import com.jy.api.dao.MemberIntegralDao;
import com.jy.api.domain.MemberIntegral;
import com.jy.api.service.MemberIntegralService;
import com.jy.api.signUpReq.admin.MemberIntegralReq;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by xiaohua on 2019/4/30.
 */
@Service
public class MemberIntegralServiceImpl implements MemberIntegralService {
    @Autowired
    private MemberIntegralDao integralDao;


    @Override
    public MemberIntegral findByStoreId(String storeId) {
        MemberIntegral integral = integralDao.findByStoreId(storeId);
        return integral;
    }

    @Override
    @Transactional
    public void UpdateIntegralOrSave(MemberIntegralReq req) {
        MemberIntegral integral;
        if (0 == req.getId()) {
            integral = new MemberIntegral();
            BeanUtils.copyProperties(req, integral);
        } else {
            integral = integralDao.findOne(req.getId());
            BeanUtils.copyProperties(req, integral);
        }
        integralDao.save(integral);
    }


}
